﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Shared/MasterPage.master" %>

<%@ Register Assembly="Typps" Namespace="Typps" TagPrefix="t" %>
<script runat="server">
    protected void ImagePicker1_ImageUploaded(object sender,
        UploadedImageFileEventArgs e)
    {
        try
        {
            // Specify the path on the server to
            // save the uploaded file to.
            string savePath = @"c:\temp\uploads\";

            HttpPostedFile hpf = e.PostedImageFile;
            // Get the name of the file to upload.
            string fileName = hpf.FileName;

            // Append the name of the file to upload to the path.
            savePath += fileName;


            // Call the SaveAs method to save the 
            // uploaded file to the specified path.
            // This example does not perform all
            // the necessary error checking.               
            // If a file with the same name
            // already exists in the specified path,  
            // the uploaded file overwrites it.
            //hpf.SaveAs(savePath);

            // Notify the client side of the name of the file
            // and path it was saved under, in case you want
            //this information client side
            e.MessageToClient = fileName;//savePath;
        }
        catch (Exception ex)
        {
            //Uploading files can be an error-prone affair. It is important to 
            //upload files in your code using proper exception handling. Typical problem 
            //is not having write permissions to the folder etc. In the end, it's your call.
        }
    }
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <style type="text/css">
        .margin
        {
            margin: 10px;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <h1>Typps Image picker</h1>
    <h2>
        Uploading images</h2>
    <div class="margin">
        (click the icon below to launch the Image uploader)</div>
    <t:ImagePicker ID="ImagePicker1" runat="server" 
        ImageUploadEnabled="true" 
        ImageBrowserEnabled="false"
        OnClientOkButton="ImagePicker1_OK" 
        DisplayImageDesignerAttributes="false" 
        DisplayImageDesignerUrlField="false"
        OnImageUploaded="ImagePicker1_ImageUploaded">
    </t:ImagePicker>
    <span id="label1" class="margin"></span>

    <script type="text/javascript">
        var label1=$get('label1');
        function ImagePicker1_OK(sender,args) {
            if(label1!=null) {
                var savedPath=args.get_commandArgument();
                if(savedPath.length>0)
                    label1.innerHTML=String.format("The file {0} was uploaded successfully",args.get_commandArgument());
                else
                    label1.innerHTML='File wasn\'t saved';
            }
        }
    </script>
</asp:Content>
